﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Algobox.Structure.Finance.Prices;
using Algobox.Objects.Finance.Assets.Stock;
using Algobox.Objects.Finance;
using Algobox.Structure.Finance.Strategies.SpikeArb;


namespace Algobox.Structure.Finance.Strategies.SpikeArb
{
    public class SpikeArbStockView : INotifyPropertyChanged
    {
        public SpikeArbStockView(SpikeArbStock strategy)
        {
            _strategy = strategy;
        }

        SpikeArbStock _strategy;

        public string Symbol { get { return _strategy.Stock.Symbol; } }

        public bool IsEnabled 
        { 
            get { return IsEnabledPrimary && IsEnabledChix && IsEnabledBats; } 
            set 
            {
                if (value ^ _strategy.ListingPrimary.IsEnabled)
                {
                    _strategy.ListingPrimary.IsEnabled = value;
                    NotifyPropertyChanged("IsEnabledPrimary");
                }
                if (value ^ _strategy.ListingChix.IsEnabled)
                {
                    _strategy.ListingChix.IsEnabled = value;
                    NotifyPropertyChanged("IsEnabledChix");
                }
                if (value ^ _strategy.ListingBats.IsEnabled)
                {
                    _strategy.ListingBats.IsEnabled = value;
                    NotifyPropertyChanged("IsEnabledBats");
                }
                NotifyPropertyChanged("IsEnabled");                
            } 
        }
        public bool IsEnabledPrimary { get { return _strategy.ListingPrimary.IsEnabled; } set { _strategy.ListingPrimary.IsEnabled = value; NotifyPropertyChanged("IsEnabledPrimary"); NotifyPropertyChanged("IsEnabled"); } }
        public bool IsEnabledChix { get { return _strategy.ListingChix.IsEnabled; } set { _strategy.ListingChix.IsEnabled = value; NotifyPropertyChanged("IsEnabledChix"); NotifyPropertyChanged("IsEnabled"); } }
        public bool IsEnabledBats { get { return _strategy.ListingBats.IsEnabled; } set { _strategy.ListingBats.IsEnabled = value; NotifyPropertyChanged("IsEnabledBats"); NotifyPropertyChanged("IsEnabled"); } }

        public bool Collar1Enabled { get { return _strategy.Collar1 != null ? _strategy.Collar1.IsEnabled : false; } set { _strategy.ToggleCollar(SpikeArbStock.SpikeArbCollar.Collar1); NotifyPropertyChanged("Collar1Enabled"); } }
        public double Collar1Pct { get { return _strategy.Collar1 != null ? _strategy.Collar1.Percentage : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar1, value, Collar1Val, Collar1Win); NotifyPropertyChanged("Collar1Enabled"); NotifyPropertyChanged("Collar1Pct"); } }
        public double Collar1Val { get { return _strategy.Collar1 != null ? _strategy.Collar1.Value : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar1, Collar1Pct, value, Collar1Win); NotifyPropertyChanged("Collar1Enabled"); NotifyPropertyChanged("Collar1Val"); } }
        public double Collar1Win { get { return _strategy.Collar1 != null ? _strategy.Collar1.Window : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar1, Collar1Pct, Collar1Val, value); NotifyPropertyChanged("Collar1Enabled"); NotifyPropertyChanged("Collar1Win"); } }

        public bool Collar2Enabled { get { return _strategy.Collar2 != null ? _strategy.Collar2.IsEnabled : false; } set { _strategy.ToggleCollar(SpikeArbStock.SpikeArbCollar.Collar2); NotifyPropertyChanged("Collar2Enabled"); } }
        public double Collar2Pct { get { return _strategy.Collar2 != null ? _strategy.Collar2.Percentage : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar2, value, Collar2Val, Collar2Win); NotifyPropertyChanged("Collar2Enabled"); NotifyPropertyChanged("Collar2Pct"); } }
        public double Collar2Val { get { return _strategy.Collar2 != null ? _strategy.Collar2.Value : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar2, Collar2Pct, value, Collar2Win); NotifyPropertyChanged("Collar2Enabled"); NotifyPropertyChanged("Collar2Val"); } }
        public double Collar2Win { get { return _strategy.Collar2 != null ? _strategy.Collar2.Window : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar2, Collar2Pct, Collar2Val, value); NotifyPropertyChanged("Collar2Enabled"); NotifyPropertyChanged("Collar2Win"); } }

        public bool Collar3Enabled { get { return _strategy.Collar3 != null ? _strategy.Collar3.IsEnabled : false; } set { _strategy.ToggleCollar(SpikeArbStock.SpikeArbCollar.Collar3); NotifyPropertyChanged("Collar3Enabled"); } }
        public double Collar3Pct { get { return _strategy.Collar3 != null ? _strategy.Collar3.Percentage : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar3, value, Collar3Val, Collar3Win); NotifyPropertyChanged("Collar3Enabled"); NotifyPropertyChanged("Collar3Pct"); } }
        public double Collar3Val { get { return _strategy.Collar3 != null ? _strategy.Collar3.Value : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar3, Collar3Pct, value, Collar3Win); NotifyPropertyChanged("Collar3Enabled"); NotifyPropertyChanged("Collar3Val"); } }
        public double Collar3Win { get { return _strategy.Collar3 != null ? _strategy.Collar3.Window : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar3, Collar3Pct, Collar3Val, value); NotifyPropertyChanged("Collar3Enabled"); NotifyPropertyChanged("Collar3Win"); } }

        public bool Collar4Enabled { get { return _strategy.Collar4 != null ? _strategy.Collar4.IsEnabled : false; } set { _strategy.ToggleCollar(SpikeArbStock.SpikeArbCollar.Collar4); NotifyPropertyChanged("Collar4Enabled"); } }
        public double Collar4Pct { get { return _strategy.Collar4 != null ? _strategy.Collar4.Percentage : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar4, value, Collar4Val, Collar4Win); NotifyPropertyChanged("Collar4Enabled"); NotifyPropertyChanged("Collar4Pct"); } }
        public double Collar4Val { get { return _strategy.Collar4 != null ? _strategy.Collar4.Value : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar4, Collar4Pct, value, Collar4Win); NotifyPropertyChanged("Collar4Enabled"); NotifyPropertyChanged("Collar4Val"); } }
        public double Collar4Win { get { return _strategy.Collar4 != null ? _strategy.Collar4.Window : 0; } set { _strategy.SetCollar(SpikeArbStock.SpikeArbCollar.Collar4, Collar4Pct, Collar4Val, value); NotifyPropertyChanged("Collar4Enabled"); NotifyPropertyChanged("Collar4Win"); } }

        public SpikeArbStock.ExitPercentages ExitPercentage { get { return _strategy.ExitPercentage; } set { _strategy.ExitPercentage = value; NotifyPropertyChanged("ExitPercentage"); } }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

    }
}
